//
//  HYTradeHeaderView.m
//  HaiYue
//
//  Created by skyline on 2018/1/23.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "HYTradeHeaderView.h"
@interface HYTradeHeaderView()
@property (nonatomic, strong) HYButton *firstBtn;
@property (nonatomic, strong) HYButton *secondBtn;
@property (nonatomic, strong) HYButton *thirdBtn;
@end
@implementation HYTradeHeaderView
- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.backgroundColor = [UIColor whiteColor];
        self.firstBtn.hidden = self.secondBtn.hidden = self.thirdBtn.hidden = NO;
        [self setupLine];
    }
    return self;
}

- (HYButton *)firstBtn
{
    if (!_firstBtn)
    {
        _firstBtn = [[HYButton alloc] initWithTitle:@"最新发布" normalImageName:@"xiala" selectImageName:@"shangla"];
        _firstBtn.titleLabel.font = [UIFont systemFontOfSize:DefaultFont];
        _firstBtn.position = HYButtonImageRightPosition;
        _firstBtn.tag = 201;
        [_firstBtn addTarget:self action:@selector(actionForHeaderSubBtn:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_firstBtn];
        [_firstBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self);
            make.top.equalTo(self);
            make.bottom.equalTo(self);
            make.width.mas_equalTo(SCREEN_WIDTH / 3.0);
        }];
    }
    return _firstBtn;
}

- (HYButton *)secondBtn
{
    if (!_secondBtn)
    {
        _secondBtn = [[HYButton alloc] initWithTitle:@"选择游戏" normalImageName:@"xiala" selectImageName:@"shangla"];
        _secondBtn.titleLabel.font = [UIFont systemFontOfSize:DefaultFont];
        _secondBtn.position = HYButtonImageRightPosition;
        _secondBtn.tag = 202;
        [_secondBtn addTarget:self action:@selector(actionForHeaderSubBtn:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_secondBtn];
        [_secondBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(self);
            make.bottom.equalTo(self);
            make.width.mas_equalTo(SCREEN_WIDTH / 3.0);
        }];
    }
    return _secondBtn;
}

- (HYButton *)thirdBtn
{
    if (!_thirdBtn)
    {
        _thirdBtn = [[HYButton alloc]initWithFrame:CGRectMake(0, 0, 80, 25) title:@"成交动态" titleColor:THEME_COLOR];
        _thirdBtn.titleLabel.font = [UIFont systemFontOfSize:DefaultFont weight:UIFontWeightLight];
        _thirdBtn.type = CCShapeLayerTypeLeftHalfEllipse;
        _thirdBtn.strokeColor = _thirdBtn.titleLabel.textColor;
        _thirdBtn.fillColor = RGBA(0, 206, 206, 0.1);
        _thirdBtn.tag = 203;
        [_thirdBtn addTarget:self action:@selector(actionForHeaderSubBtn:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_thirdBtn];
        [_thirdBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self);
            make.centerY.equalTo(self);
            make.size.mas_equalTo(self.thirdBtn.bounds.size);
        }];
    }
    return _thirdBtn;
}

- (void)setFirstTitle:(NSString *)firstTitle
{
    if (_firstTitle != firstTitle)
    {
        _firstTitle = firstTitle;
        [self.firstBtn setTitle:_firstTitle forState:UIControlStateNormal];
        self.firstBtn.selected = !self.firstBtn.selected;
    }
}

- (void)setupLine
{
    for (int i = 1; i < 3; i++)
    {
        HYView *line = [[HYView alloc] initWithColor:LINE_COLOR];
        [self addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).with.offset(GAP / 2.0);
            make.bottom.equalTo(self).with.offset(- GAP / 2.0);
            make.left.equalTo(self).with.offset(SCREEN_WIDTH / 3.0 * i - 1.0);
            make.width.mas_equalTo(1.0);
        }];
    }
}

- (void)actionForHeaderSubBtn:(HYButton *)sender
{
    sender.selected = (sender.tag == 201)?!sender.selected:sender.selected;
    if (self.delegate && [self.delegate respondsToSelector:@selector(methodSignatureForSelector:)])
    {
        [self.delegate methodForHYTradeHeaderViewDelegateWithTag:sender.tag];
    }
    
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
